//
//  DeviceBindTipsVC.m
//  xychain_DM_iOS
//
//  Created by Jpwang on 2018/6/25.
//  Copyright © 2018年 Jpwang. All rights reserved.
//

#import "DeviceBindTipsVC.h"

@interface DeviceBindTipsVC () {
    int mType;
    NSString *mText;
    void (^mBlock)(int clickType, int type);
}

@property(weak, nonatomic)IBOutlet UIView *conView;
@property(weak, nonatomic)IBOutlet UIView *topView;
@property(weak, nonatomic)IBOutlet UIImageView *iconIv;
@property(weak, nonatomic)IBOutlet UILabel *titleLb;
@property(weak, nonatomic)IBOutlet UILabel *descLb;
@property(weak, nonatomic)IBOutlet UIButton *leftBt;
@property(weak, nonatomic)IBOutlet UIButton *rightBt;
@property(weak, nonatomic)IBOutlet NSLayoutConstraint *scale;

@end

@implementation DeviceBindTipsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setType:(int)type text:(NSString *)txt  block:(void (^)(int clickType, int type))block; {
    mType = type;
    mText = txt;
    mBlock = [block copy];
}

- (void)initView {
    self.conView.layer.cornerRadius = globalRadius;
    if (mType==0) {
        [self.scale setValue:[NSNumber numberWithFloat:1] forKey:@"multiplier"];
        [self.descLb setHidden:YES];
        self.iconIv.image = [UIImage imageNamed:@"right"];
        self.titleLb.text = @"设备绑定成功！";
        [self.leftBt setTitle:@"确定" forState:UIControlStateNormal];
        [self.rightBt setTitle:@"继续绑定" forState:UIControlStateNormal];
    } else {
        [self.scale setValue:[NSNumber numberWithFloat:0.7] forKey:@"multiplier"];
        [self.descLb setHidden:NO];
        self.iconIv.image = [UIImage imageNamed:@"error"];
        self.titleLb.text = @"绑定未成功！";
        self.descLb.text = mText;
        [self.leftBt setTitle:@"退出" forState:UIControlStateNormal];
        [self.rightBt setTitle:@"重试" forState:UIControlStateNormal];
    }
    [[self.leftBt rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        if (self->mBlock) {
            self->mBlock(0, self->mType);
        }
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    [[self.rightBt rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        if (self->mBlock) {
            self->mBlock(1, self->mType);
        }
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
}

//case 1: {
//    isAni = NO;
//    self.stateIv.transform = CGAffineTransformMakeRotation(0);
//    self.stateIv.image = [UIImage imageNamed:@"right"];
//    self.stateLb.text = @"设备绑定成功";
//    break;
//}
//case 2: {
//    isAni = YES;
//    [self startAnimation];
//    self.stateIv.image = [UIImage imageNamed:@"loading"];
//    self.stateLb.text = @"设备绑定中";
//    break;
//}
//case 3: {
//    isAni = NO;
//    self.stateIv.transform = CGAffineTransformMakeRotation(0);
//    self.stateIv.image = [UIImage imageNamed:@"error"];
//    self.stateLb.text = msg && msg.length>8 ? msg : @"绑定失败";
//    break;
//}


@end
